#ifndef __SHAREDFILE_H__
#define __SHAREDFILE_H__

#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include "Constants.h"
#include "SharedRecord.h"

using namespace std;

class SharedFile {

private:
	fstream file;
	int fd;
	struct flock fl;

	string getDefaultSharedFile();
	void init(string path);

public:
	SharedFile();
	SharedFile(string path);
	virtual ~SharedFile();

	SharedRecord getNextRecord();
	void addRecord(SharedRecord record);
	void removeRecord(SharedRecord record);
	bool isEOF();
	long int currentPosition();
	void goTo(long int position);
	void goToEnd();
	int getWriteLock();
	int getReadLock();
	int unlock();
};

#endif /* __SHAREDFILE_H__ */
